package dl.demo.repository;

import dl.demo.entity.Project;
import io.swagger.models.auth.In;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ProjectRepo extends JpaRepository<Project.Project_p,Integer> {

    @Query(value="select p.id as id, p.name as name, introduction, ispublic, createtime, " +
            "       edittime, user_id, image_id, stars, folks, views, u.username as username " +
            "from (project p inner join project_example pe on p.id = pe.project_id) " +
            "inner join user u on u.id = p.user_id",nativeQuery = true)
    List<Project> getProjectExamples();

    @Query(value = "select * from project where user_id = ?1 ",nativeQuery = true)
    List<Project> getProjectsByUser(@Param("name") String id);

    @Query(value = "select * from project p inner join star s " +
            "on p.id = s.project_id and s.user_id = ?1",nativeQuery = true)
    List<Project> getProjectsByStar(Integer user_id);
}
